/* -----------------
* brief
* 1. this is code gen by tools
 */

package service

import (
	"fmt"
	"github.com/mjiulee/lego"
	. "saas_sys_base/modules/tenant/models"
)

type TenantWxCardMchService struct {
	// add your model here
	tbTenantWxCardMch TenantWxCardMch
}

func (t *TenantWxCardMchService) ListTenantWxCardMch(keyword string, page, psize int, orderField, order string) ([]map[string]string, int64, error) {
	// 业务查询
	queryMap := map[string]interface{}{
		"table":  map[string]string{"table": "tb_tenant_wx_card_mch", "alias": "t1"},
		"fields": []string{"t1.*"},
		"join":   []map[string]string{
			// map[string]string{"table": "tb_xx as t2", "on": "t2.xid = t1.id"},
		},
		"where": []lego.QMapWhereField{
			{"t1.if_del", "=", 0, "AND", false},
		},
		"search": map[string]string{
			//"t1.id": req.Keyword,
		},
		"orders": []string{"t1.id asc"},
		"page": map[string]int{
			"page":  page,
			"psize": psize,
		},
	}

	if orderField != "" && order != "" {
		orderStr := fmt.Sprintf("t1.%s %s", orderField, order)
		queryMap["orders"] = []string{orderStr, "t1.cdate asc"}
	}

	return lego.QueryListByMap(queryMap)
}

/* 根据id获取记录
 * -----------------
 */
func (t *TenantWxCardMchService) GetTenantWxCardMchById(id int64) *TenantWxCardMch {
	return t.tbTenantWxCardMch.RecodeById(id)
}

/* 添加
 * -----------------
 */
func (t *TenantWxCardMchService) SaveTenantWxCardMch(item2add *TenantWxCardMch) bool {
	return t.tbTenantWxCardMch.AddRecode(item2add)
}

/* 删除(硬删除)*/
func (t *TenantWxCardMchService) DelTenantWxCardMchById(id int64) bool {
	return t.tbTenantWxCardMch.DelRecodeById(id)
}

/* 更新
 * -----------------*/
func (t *TenantWxCardMchService) UpdateTenantWxCardMch(rc *TenantWxCardMch) bool {
	return t.tbTenantWxCardMch.UpdateRecode(rc)
}
